package com.fingard.dsp.bank.directbank.boc01;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directConfig.NodeSalaryItem;
import com.fingard.dsp.bank.directConfig.SalaryConfig;
import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
import com.fingard.dsp.salaryset.SalaryDecrypt;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.util.RSAEncryptHelper;
import com.fingard.util.secret.salary.DESUtil;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component("BOC01BatPayRec")
public class BOC01BatPayRec extends BOC01Base implements IBatPayRec {
    /**
     * 批量代付提交
     * @param p_req1988 批量代付请求对象
     * @return
     * @throws Exception
     */
    //1988
    @Override
    public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception {
        return d_BatPayRec(p_req1988);
    }

    /**
     * 批量代扣提交
     * @param p_req9188 批量代扣请求对象
     * @return
     * @throws Exception
     */
    //9188
    @Override
    public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception {
        return d_BatPayRec(p_req9188);
    }

    //批量代收和批量代付提交
    public RetAtsBatPayRec d_BatPayRec(ReqBatPayRec p_reqBat) throws Exception {
        //返回ATS的对象
        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_reqBat.reqHeader);

        String enableSalaryDecrypt = getBankConfig().getValueAsString("enableSalaryDecrypt");
        String commedTypeArrs = getBankConfig().getValueAsString("salaryDecryptCommand");
        if ("true".equals(enableSalaryDecrypt) && StringHelper.hasAnyChar(commedTypeArrs)) {
            String[] arrs = commedTypeArrs.split(",");
            List<String> list = Arrays.asList(arrs);
            if (list.contains(p_reqBat.reqHeader.commandCode)) {
                if (StringHelper.isNullOrEmpty(p_reqBat.decryptKey)) {
                    throw new Exception("获取密钥失败");
                }
                p_reqBat.decryptKey = RSAEncryptHelper.base64PlusRSADecryptAndUncompress(p_reqBat.decryptKey, "utf-8", SalaryDecrypt.rsaPrivateKey);
                p_reqBat.isNeedDecrypt = true;
                isNeedHiddleField = true;
            }
            //变换成真正的密钥
            if (StringHelper.hasAnyChar(p_reqBat.decryptKey)) {
                String key = p_reqBat.reqHeader.bankCode + "-" + p_reqBat.reqHeader.corporation
                        + "-" + p_reqBat.reqHeader.group;
                SalaryConfig salaryConfig = SalaryDecrypt.getSalaryConfig(key);
                if (salaryConfig == null) {
                    throw new Exception("获取渠道：" + key + " 的解密配置失败");
                }
                Map<String, NodeSalaryItem> map = salaryConfig.nodeSalaryItemMap;
                p_reqBat.salaryItemMap = map;
                if (map.keySet().contains("TotalAmount")) {
                    NodeSalaryItem item = map.get("TotalAmount");
                    String totalAmt = DESUtil.jdkDESDecryptMode(p_reqBat.totalAmt, p_reqBat.decryptKey);
                    if (StringHelper.hasAnyChar(totalAmt)) {
                        p_reqBat.totalAmt = totalAmt.split(item.union)[item.index - 1];
                    }
                }
            }
        }
        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            if (p_reqBat.reqHeader.transType.equals("1988")) {
                bankHeader.trncod = "b2e0078";//交易代码
            } else if (p_reqBat.reqHeader.transType.equals("9188")) {
                bankHeader.trncod = "b2e0191";//交易代码
            }
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            writeCommonHeader(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            if (bankHeader.trncod.equals("b2e0078")) {
                xmlWriter.writeElementClosed("ceitinfo");
                xmlWriter.writeElementClosed("transtype");
            }
            xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
            xmlWriter.writeElementString("insid", p_reqBat.reqBatchNO);
            if (bankHeader.trncod.equals("b2e0078")) {
                xmlWriter.writeStartElement("fractn");
                xmlWriter.writeElementString("fribkn", p_reqBat.ownArea);
                xmlWriter.writeElementString("actacn", p_reqBat.ownAct);
                xmlWriter.writeElementString("actnam", p_reqBat.ownActName);
                xmlWriter.writeEndElement();
                //xmlWriter.writeElementString("telephone", "",true);
                xmlWriter.writeElementString("pybcur", this.convertCurToBank(p_reqBat.ownCur));
                xmlWriter.writeElementString("pybamt", p_reqBat.totalAmt);
                xmlWriter.writeElementString("pybnum", p_reqBat.totalNum);
                if (p_reqBat.sameBnk.equals("1")) {//crdtyp 6：他行	7：我行
                    xmlWriter.writeElementString("crdtyp", "7");
                } else {
                    xmlWriter.writeElementString("crdtyp", "6");
                }
            } else if (bankHeader.trncod.equals("b2e0191")) {
                xmlWriter.writeElementString("toibkn", p_reqBat.ownArea);
                xmlWriter.writeElementString("toactacn", p_reqBat.ownAct);
                xmlWriter.writeElementString("cdate", Format.Date8Format.format(new Date()));
                if (p_reqBat.sameBnk.equals("1")) {//paytyp 1：中行 0：他行
                    xmlWriter.writeElementString("paytyp", "1");
                } else {
                    xmlWriter.writeElementString("paytyp", "0");
                }
                xmlWriter.writeElementString("txncur", this.convertCurToBank(p_reqBat.ownCur));
                xmlWriter.writeElementString("pybamt", p_reqBat.totalAmt);
                xmlWriter.writeElementString("pybnum", p_reqBat.totalNum);
            }

            String furinfo = getBankConfig().getMapValueByKey("furinfo" + bankHeader.trncod, p_reqBat.useType);
            //String useinf = p_reqBat.useBat;
            //if(useinf.length()> 30){
            //	useinf = useinf.substring(0,31);
            //}
            //useinf=useinf+"-"+p_reqBat.abstractATS;
            if (bankHeader.trncod.equals("b2e0078")) {
                xmlWriter.writeElementString("furinfo", furinfo);
                String useinf = this.getBankConfig().getValueAsBool("unsetAbstr2b2e0078useinf") ? "" : p_reqBat.abstractATS;
                xmlWriter.writeElementString("useinf", useinf);
                xmlWriter.writeElementString("trfdate", Format.Date8Format.format(new Date()));
            } else if (bankHeader.trncod.equals("b2e0191")) {
                xmlWriter.writeElementString("useinf", furinfo);
                xmlWriter.writeElementString("furinfo", p_reqBat.abstractATS);
            }
            //需要进行对账码拼接以及节点解析，采用XElement进行处理
            while (p_reqBat.readRecord()) {
                XElement tmpXElement = new XElement("detail", "");

                String area = "";
                String standardArea = "";
                if (bankHeader.trncod.equals("b2e0078")) {//代付
                    area = p_reqBat.readedDetail.recArea;
                    standardArea = p_reqBat.readedDetail.recStandardArea;
                } else if (bankHeader.trncod.equals("b2e0191")) {//代收
                    area = p_reqBat.readedDetail.payArea;
                    standardArea = p_reqBat.readedDetail.payStandardArea;
                }
                String areaMapped = "";
                if (StringHelper.hasAnyChar(area)) {
                    areaMapped = getBankConfig().getMapValueByKey("areaMapping", area);
                }
                if (StringHelper.isNullOrEmpty(areaMapped)) {
                    areaMapped = getBankConfig().getMapValueByKey("areaMapping", standardArea);
                }

                if (bankHeader.trncod.equals("b2e0078")) {//代付
                    if (p_reqBat.readedDetail.sameBnk.equals("1")) {
                        tmpXElement.addChild(new XElement("toibkn", areaMapped));
                    } else {
                        tmpXElement.addChild(new XElement("toibkn", p_reqBat.readedDetail.cnapsCode));
                    }
                    tmpXElement.addChild(new XElement("tobank", p_reqBat.readedDetail.getOppBankLocation()));
                    tmpXElement.addChild(new XElement("toactn", p_reqBat.readedDetail.recAct));
                    tmpXElement.addChild(new XElement("pydcur", this.convertCurToBank(p_reqBat.readedDetail.payCur)));
                    tmpXElement.addChild(new XElement("pydamt", p_reqBat.readedDetail.payAmount));
                    tmpXElement.addChild(new XElement("toname", p_reqBat.readedDetail.recName));
                    tmpXElement.addChild(new XElement("toidtp", ""));
                    tmpXElement.addChild(new XElement("toidet", ""));
                    tmpXElement.addChild(new XElement("furinfo", p_reqBat.readedDetail.askNumber));
                    tmpXElement.addChild(new XElement("purpose", ""));
                    tmpXElement.addChild(new XElement("reserve1", ""));
                    tmpXElement.addChild(new XElement("reserve2", ""));
                    tmpXElement.addChild(new XElement("reserve3", ""));
                    tmpXElement.addChild(new XElement("reserve4", ""));
                } else if (bankHeader.trncod.equals("b2e0191")) {//代收
                    if (p_reqBat.readedDetail.sameBnk.equals("1")) {
                        tmpXElement.addChild(new XElement("bcode", areaMapped));
                    } else {
                        tmpXElement.addChild(new XElement("bcode", p_reqBat.readedDetail.cnapsCode));
                    }
                    tmpXElement.addChild(new XElement("fractacn", p_reqBat.readedDetail.payAct));
                    tmpXElement.addChild(new XElement("frname", p_reqBat.readedDetail.payName));
                    tmpXElement.addChild(new XElement("fridtp", convertCertTypeToBank(p_reqBat.readedDetail.certType)));
                    tmpXElement.addChild(new XElement("fridet", p_reqBat.readedDetail.certNum));
                    tmpXElement.addChild(new XElement("pydamt", p_reqBat.readedDetail.payAmount));
                    tmpXElement.addChild(new XElement("agrno", ""));
                    tmpXElement.addChild(new XElement("furinfo", p_reqBat.readedDetail.askNumber));
                    tmpXElement.addChild(new XElement("useinf", ""));
                }
                xmlWriter.writeXElement(tmpXElement);
            }
            xmlWriter.writeEndDocument();//写入报文完成
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());//发送银行
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                //解析银行返回
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");
                    String tmprsperrcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspcod");
                    String tmprsperrmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                    if (isActiveRetCode(tmprspcod)) {
                        if (tmpBkReader.read("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs")) {
                            retAts.respCode = "0";
                            retAts.transState = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                            retAts.payInfoCode = retAts.transState;
                            retAts.respInfo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                            retAts.reqSeqID = tmpBkReader.readedXElement.getSingleText("insid");
                        } else {
                            retAts.respCode = "0";
                            retAts.transState = tmprspcod;
                            retAts.payInfoCode = tmprspcod;
                            retAts.respInfo = tmprspmsg;
                            retAts.reqSeqID = p_reqBat.reqBatchNO;
                        }
                    } else if (StringHelper.hasAnyChar(tmprsperrcod)) {
                        retAts.respCode = "0";
                        retAts.transState = "err+" + tmprsperrcod;
                        retAts.payInfoCode = retAts.transState;
                        retAts.respInfo = tmprsperrmsg;
                        retAts.reqSeqID = p_reqBat.reqBatchNO;
                    } else {
                        retAts.respCode = "-1";
                        retAts.transState = tmprspcod;
                        retAts.respInfo = tmprspmsg;
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                }
            } else if (tmpStrRet[0].equals(ConnState.FAIL)) {
                retAts.respCode = "0";
                retAts.respInfo = tmpStrRet[1];
                retAts.reqSeqID = p_reqBat.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = tmpStrRet[0];
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
            }

        } catch (
                Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.toString();
            e.printStackTrace();
        }
        if (retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_reqBat.reqBatchNO;
        }
        retAts.writeRetToATS();
        return retAts;
    }

    /**
     * 批量代付状态查询
     * @param p_reqQryBat
     * @return
     * @throws Exception
     */
    //1998 状态查询
    @Override
    public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_reqQryBat) throws Exception {
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_reqQryBat.reqHeader);
        retAts.reqSeqID = p_reqQryBat.reqBatchNO;
        retAts.respCode = "";

        try {
            int begnum = 1;
            while (!retAts.respCode.equals("-1")) {//分页查询
                BOC01Header bankHeader = new BOC01Header();
                bankHeader.trncod = "b2e0079";
                bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
                xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
                xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
                xmlWriter.writeElementClosed("obssid");
                xmlWriter.writeElementString("insid", p_reqQryBat.reqBatchNO);

                xmlWriter.writeElementString("begnum", String.valueOf(begnum));
                xmlWriter.writeElementString("recnum", "500");

                xmlWriter.writeEndDocument();

                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                        String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");
                        if (StringHelper.hasAnyChar(tmprspcod)) {
                            String tmpStrPybnum = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/pybnum");
                            String detailNode = "/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs";
                            int tmpCountRow = tmpBkReader.countElement(detailNode);
                            if (tmpCountRow > 0) {
                                if (tmpCountRow == 1) {
                                    String rspcode = tmpBkReader.getFirstText(detailNode + "/status/rspcod");
                                    String rspmsg = tmpBkReader.getFirstText(detailNode + "/status/rspmsg");
                                    if ("B052".equals(rspcode)) {
                                        if (canBeNotExist(p_reqQryBat, retAts, 60)) {
                                            retAts.respCode = "0";
                                            retAts.respInfo = rspmsg;
                                            retAts.transState = StringHelper.joinNotEmpty("+", rspcode, rspmsg);
                                            retAts.payInfoCode = retAts.transState;
                                        }
                                        break;
                                    }
                                }
                                if (begnum == 1) {
                                    retAts.respCode = "0";
                                    retAts.writeBeforeDetail();
                                }
                                while (tmpBkReader.read(detailNode)) {
                                    RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                    tmpRetDetail.result = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                                    tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("status/rspmsg");
                                    tmpRetDetail.recAct = tmpBkReader.readedXElement.getSingleText("toactn");
                                    tmpRetDetail.recName = tmpBkReader.readedXElement.getSingleText("toname");
//                                    if(!isNeedHiddleField) {
//                                        tmpRetDetail.payAmount = tmpBkReader.readedXElement.getSingleText("pydamt");
//                                    }
                                    tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("furinfo");
                                    tmpRetDetail.payInfoCode = tmpRetDetail.result;
                                    retAts.writeRetDetail(tmpRetDetail);
                                }
                                begnum = tmpCountRow + begnum;
                                if (StringHelper.hasAnyChar(tmpStrPybnum)) {
                                    int tmpIntPybnum = Integer.parseInt(tmpStrPybnum);
                                    if (begnum > tmpIntPybnum) {
                                        break;
                                    }
                                }
                            } else if (tmpCountRow == 0) {
                                retAts.respCode = "0";
                                retAts.transState = tmprspcod + "+" + tmprspmsg;
                                retAts.respInfo = tmprspmsg;
                                retAts.payInfoCode = tmprspcod;
                                break;
                            } else {
                                retAts.respCode = "-1";
                                retAts.respInfo = tmprspmsg;
                                break;
                            }
                        } else {
                            retAts.respCode = "-1";
                            retAts.respInfo = tmprspmsg;
                            break;
                        }
                    } else {
                        retAts.respCode = "-1";
                        retAts.respInfo = tmpSbMsg.toString();
                        break;
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpStrRet[1];
                    break;
                }
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            e.printStackTrace();
        }
        /*if (retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
        }
        if (retAts.respCode.equals("-1")) {
            retAts.writeBeforeDetail();
        }*/
        retAts.writeAfterDetail();
        return retAts;
    }

    /**
     * 批量代扣状态查询
     * @param p_reqQryBat
     * @return
     * @throws Exception
     */
    //9198
    @Override
    public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_reqQryBat) throws Exception {
        //返回ATS的对象
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_reqQryBat.reqHeader);
        retAts.respCode = "";

        try {

            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trncod = "b2e0190";
            bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            writeCommonHeader(xmlWriter, bankHeader);//写入通用的头部节点
            xmlWriter.writeStartElement("trn-" + bankHeader.trncod + "-rq");
            xmlWriter.writeStartElement(bankHeader.trncod + "-rq");
            xmlWriter.writeElementClosed("obssid");
            xmlWriter.writeElementString("insid", p_reqQryBat.reqBatchNO);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod1 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg1 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/status/rspmsg");

                    String tmprspcod2 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/status/rspcod");
                    String tmprspmsg2 = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/status/rspmsg");

                    if (StringHelper.hasAnyChar(tmprspcod1) && StringHelper.hasAnyChar(tmprspcod2)) {
                        retAts.reqSeqID = tmpBkReader.getFirstText("/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/insid");
                        String detailNode = "/bocb2e/trans/trn-" + bankHeader.trncod + "-rs/" + bankHeader.trncod + "-rs/detail";
                        int tmpCountRow = tmpBkReader.countElement(detailNode);
                        if (tmpCountRow > 0) {
                            retAts.respCode = "0";
                            retAts.writeBeforeDetail();
                            while (tmpBkReader.read(detailNode)) {
                                RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();

                                tmpRetDetail.result = tmprspcod2 + "+" + tmpBkReader.readedXElement.getSingleText("trfsta");
                                tmpRetDetail.memo = tmpBkReader.readedXElement.getSingleText("promsg");
                                tmpRetDetail.payAct = tmpBkReader.readedXElement.getSingleText("fractacn");
                                tmpRetDetail.payName = tmpBkReader.readedXElement.getSingleText("frname");
                                tmpRetDetail.payAmount = tmpBkReader.readedXElement.getSingleText("pydamt");
                                tmpRetDetail.postScript = tmpBkReader.readedXElement.getSingleText("furinfo");
                                tmpRetDetail.payInfoCode = tmpRetDetail.memo;
                                if(StringHelper.isNullOrEmpty(tmpRetDetail.payInfoCode)){
                                    tmpRetDetail.result = tmpRetDetail.result +"+可疑";
                                    tmpRetDetail.payInfoCode = "可疑";
                                    tmpRetDetail.memo = "可疑";
                                }

                                retAts.writeRetDetail(tmpRetDetail);
                            }
                        } else if (tmpCountRow == 0) {
                            retAts.respCode = "0";
                            retAts.transState = tmprspcod2 + "+" + tmprspmsg2;
                            retAts.respInfo = tmprspmsg2;
                            retAts.payInfoCode = tmprspcod2;
                        } else {
                            retAts.respCode = "-1";
                            retAts.respInfo = tmprspmsg2;
                        }
                    } else {
                        retAts.respCode = "-1";
                        retAts.respInfo = tmprspmsg2;
                        if (StringHelper.isNullOrEmpty(retAts.respInfo)) {
                            retAts.respInfo = tmprspmsg1;
                        }
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
            }


        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            e.printStackTrace();
        }
        if (retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
        }
        if (retAts.respCode.equals("-1")) {
            retAts.writeBeforeDetail();
        }
        retAts.writeAfterDetail();
        return retAts;
    }
}
